package kd.hc.ec;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.args.EndOperationTransactionArgs;
import kd.bos.exception.KDBizException;
import kd.bos.exception.KDException;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.sdk.plugin.Plugin;

/**
 * 单据操作
 */
public class EcProjectServicePlugIn extends AbstractOperationServicePlugIn implements Plugin {
    @Override
    public void endOperationTransaction(EndOperationTransactionArgs e) {
        super.endOperationTransaction(e);
        String operationKey = e.getOperationKey();
        switch (operationKey) {
            case "unaudit":
                DynamicObject[] dataEntities = e.getDataEntities();
                if (dataEntities != null && dataEntities.length >= 1) {
                    for (int i = 0; i < dataEntities.length; i++) {
                        DynamicObject dataEntity = dataEntities[i];
                        String id = dataEntity.getPkValue().toString();
                        DynamicObject[] projectExit = BusinessDataServiceHelper.load("ecbd_projectupdate", "id",
                                new QFilter[]{new QFilter("project", QCP.equals, id)});
                        if(projectExit!=null && projectExit.length>=1){
                            //有变更单不能反审核了
                            throw new KDBizException("不允许反审核修改项目基础资料请走项目变更单!");
                        }
                    }
                }
                break;
        }

    }
}